﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BadApplePlayer
{
    public partial class FrmRect : Form
    {
        public FrmRect() {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.None;
            this.Location = Point.Empty;
            this.Size = Screen.PrimaryScreen.Bounds.Size;
            this.BackColor = Color.Green;
            this.TransparencyKey = this.BackColor;
            this.ShowInTaskbar = false;
            this.TopMost = true;
            this.LostFocus += (s, e) => this.Hide();
            m_lstRectDraw = new List<Rectangle>();
        }

        private List<Rectangle> m_lstRectDraw;

        private Rectangle _rectDraw;

        public Rectangle RectDraw {
            get { return _rectDraw; }
            set { _rectDraw = value; }
        }

        public void AddSubRect(Rectangle rect) {
            m_lstRectDraw.Add(rect);
        }

        public void ClearSubRect() {
            m_lstRectDraw.Clear();
        }

        public Rectangle[] SubRectToArray() {
            return m_lstRectDraw.ToArray();
        }

        public void DrawRectangle(Rectangle rect) {
            if (_rectDraw == rect) return;
            if (!this.Visible) this.Show();
            _rectDraw = rect;
            this.Invalidate();
        }

        public void ClearRect() {
            _rectDraw = Rectangle.Empty;
            this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e) {
            using (Pen p = new Pen(Color.Cyan, 3)) {
                e.Graphics.DrawRectangle(p, _rectDraw);
                for (int i = 0, len = m_lstRectDraw.Count; i < len; i++)
                    e.Graphics.DrawRectangle(Pens.Red, m_lstRectDraw[i]);
                this.TopMost = true;
            }
            base.OnPaint(e);
        }
    }
}
